<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
class RolePrivileges {
var $id;
var $app_role_id;
var $app_module_id;
var $grant_read;
var $grant_write;
var $grant_print;
var $grant_sent;
var $grant_export;


    function open($app_role_id,$app_module_id){
        global $db;
        $sql="select id,grant_read,grant_write,grant_print,grant_sent,grant_export 
            from role_privileges 
            where app_role_id=$app_role_id 
                and app_module_id=$app_module_id";
        $this->app_role_id=$app_role_id;
        $this->app_module_id=$app_module_id;
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->id=$id;
            $this->grant_read=$grant_read;
            $this->grant_write=$grant_write;
            $this->grant_print=$grant_print;
            $this->grant_sent=$grant_sent;
            $this->grant_export=$grant_export;

        }
    }

    function openAll(){
        $sql="select * from role_privileges order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into role_privileges values (null,'{$this->app_role_id}',
'{$this->app_module_id}','{$this->grant_read}',
'{$this->grant_write}','{$this->grant_print}',
'{$this->grant_sent}','{$this->grant_export}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update role_privileges set app_role_id={$this->app_role_id},
app_module_id={$this->app_module_id},grant_read='{$this->grant_read}',
grant_write='{$this->grant_write}',grant_print='{$this->grant_print}',
grant_sent='{$this->grant_sent}',grant_export='{$this->grant_export}'
 where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from role_privileges where id=".$this->id;
        $db->query($sql);
    }

}
?>
